package com.yonginitagmaker.atv;

import java.io.IOException;
import java.nio.charset.Charset;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.yonginitagmaker.R;
import com.yonginitagmaker.common.Constants;
import com.yonginitagmaker.util.Alert;
import com.yonginitagmaker.util.Alert.OnCloseListener;
import com.yonginitagmaker.util.FormatUtil;
import com.yonginitagmaker.util.LogUtil;

public class AtvInputTagInfo extends Activity
{
	private Button				mBtnCreate		= null;
	private EditText			mEdtShopNo		= null;
	private Button				mBtnReset		= null;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.atv_input_tag_info);

		findView();
		configureListener();
	}

	private void findView()
	{
		mBtnCreate = (Button) findViewById(R.id.btnCreate);
		mEdtShopNo = (EditText) findViewById(R.id.edtShopNo);
		mBtnReset = (Button) findViewById(R.id.btnReset);
	}

	private void configureListener()
	{
		mBtnCreate.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				String shopNo = mEdtShopNo.getText().toString();
				if(FormatUtil.isNullorEmpty(shopNo))
				{
					Alert.toastLong(v.getContext(), "상점번호를 입력해 주세요.");
					mEdtShopNo.requestFocus();
					return;
				}

				Intent intent = new Intent(v.getContext(), AtvMakingTag.class);
				intent.putExtra(Constants.BUNDLE_KEY_SHOP_NO, shopNo);
				startActivityForResult(intent, Constants.REQUEST_CODE_MAKE_NFC);
			}
		});

		mBtnReset.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Alert dialog = new Alert();
				dialog.showAlert(v.getContext(), "정말 초기화 하시겠습니까?");
				dialog.setOnCloseListener(new OnCloseListener()
				{
					@Override
					public void onClose(DialogInterface dialog, int which)
					{
						mEdtShopNo.setText("");
						
					}
				});
			}
		});
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		if(requestCode == Constants.REQUEST_CODE_MAKE_NFC)
		{
			if(resultCode == Activity.RESULT_OK)
			{
				
			}
		}
		
		super.onActivityResult(requestCode, resultCode, data);
	}
}